<?php
/**
 * 红包游戏
 * User: liu
 * Date: 2017/7/11
 * Time: 16:20
 */
class Api_RedBagGame extends Api_Common {
    public function getRules() {
        return array(
            'addRedgame' => array(
                'uid'   => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'liveid'   => array('name' => 'liveid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '直播间ID'),
                'title' => array('name' => 'title', 'type' => 'string', 'min' => 1, 'require' => true, 'des c' => '主题'),
                'num'   => array('name' => 'num', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '总人数'),
                'money' => array('name' => 'money', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => '每人支付'),
            ),
            'parRedgame' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'liveid'   => array('name' => 'liveid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '直播间ID'),
                'task_id'=>  array('name' => 'task_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '红包id'),
            ),
            'redGameList' =>array(
                'uid' =>  array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'liveid'   => array('name' => 'liveid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '直播间ID'),
            ),
            'haveGamelist' =>array(
                'uid' =>  array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'liveid'   => array('name' => 'liveid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '直播间ID'),
                'status' =>  array('name' => 'status', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '类型，1,进行中 2，未拆开，3，退款中 4，已拆开 5，已退款'),
            ),
            'reddetails' => array(
                'uid' =>  array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'status' =>  array('name' => 'status', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '类型，1,进行中 2，未拆开，3，退款中 4，已拆开 5，已退款'),
                'task_id' =>  array('name' => 'task_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '任务ID'),
            ),
            'noReddetails' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'task_id'=>  array('name' => 'task_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '红包id'),
            ),
            'refund' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'task_id'=>  array('name' => 'task_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '红包id'),
            ),
            'redProfit' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
            ),
            'redrule' => array(
            ),
            'mybalance' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'task_id'=>  array('name' => 'task_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '红包id'),
            ),
            'mybalance2' => array(
                'uid'    =>   array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
            ),

        );
    }

    /**
     * 发布红包游戏
     * @desc 创建红包任务
     * @return int code 操作码，0表示成功
     * @return int code 操作码，-1发布任务失败
     * @return int code 操作码，-2播豆不足,无法支付任务金额
     * @return string msg 提示信息
     */
    public function addRedgame(){
        $rs = array('code' => 0, 'msg' => '发布任务成功', 'info' => array());

        $domain = new Domain_RedBagGame();
        $info = $domain->addRedgame($this->uid,$this->liveid,$this->title,$this->num,$this->money);

        $rs['info'][0] = $info;
        if($info==1001){
            $rs['code'] = -1;
            $rs['msg'] = '发布任务失败';
        }
        if($info == 1002){
            $rs['code'] = -2;
            $rs['msg'] = '播豆不足,无法支付任务金额';
        }
        if($info == 1003){
            $rs['code'] = -3;
            $rs['msg'] = '人数必须大于1人以上';
        }
        return $rs;
    }

    /**
     * 参与红包游戏
     * @desc 参与红包任务
     * @return int code 操作码，0表示成功
     * @return int code 操作码，-1 人数已满足，请选择别的红包
     * @return int code 操作码，-2 您已参与过此任务
     * @return string msg 提示信息
     */
    public function parRedgame(){
        $rs = array('code' => 0, 'msg' => '参与任务成功', 'info' => array());

        $domain = new Domain_RedBagGame();
        $info = $domain->parRedgame($this->uid,$this->liveid,$this->task_id);

        $rs['info'][0] = $info;
        if($info==1001){
            $rs['code'] = -1;
            $rs['msg'] = '人数已满足，请选择别的红包';
        }
        if($info==1002){
            $rs['code'] = -2;
            $rs['msg'] = '您已参与过此任务';
        }
        if($info == 1003){
            $rs['code'] = -2;
            $rs['msg'] = '播豆不足,无法支付任务金额';
        }

        if($info == 1004){
            $rs['code'] = -2;
            $rs['msg'] = '拼福失败,无法参加';
        }
        return $rs;
    }

    /**
     * 未参与红包游戏列表
     * @desc 未参与红包游戏列表
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function  redGamelist(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->redGamelist($this->uid,$this->liveid);
        $rs['info'][0] = $info;
        return $rs;
    }

    /**
     * 已参与红包游戏列表
     * @desc 已参与红包游戏列表
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public  function haveGamelist(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->haveGamelist($this->uid,$this->liveid,$this->status);
        $rs['info'][0] = $info;
        return $rs;
    }

    /**
     * 已参与红包任务详情
     * @desc 红包任务详情
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     * @request status 1,进行中 2，未拆开，3，退款中 4，已拆开 5，已退款
     */
    public function  reddetails(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->reddetails($this->uid,$this->status,$this->task_id);
        $rs['info'][0] = $info;
        return $rs;
    }

    /**
     * 未参与红包任务详情
     * @desc 未参与红包任务详情
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function noReddetails(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->noReddetails($this->uid,$this->task_id);
        $rs['info'][0] = $info;
        return $rs;
    }

    /**
     * 退款
     * @desc 退款
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function refund(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->refund($this->uid,$this->task_id);
        if($info==1000){
            $rs['code'] =0;
            $rs['msg'] = '退款成功';
        }
        if($info==10001){
            $rs['code'] = 0;
            $rs['msg'] = '退款失败';
        }
        return $rs;
    }

    /**
     * 红包收益
     * @desc 红包收益
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function redProfit(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->redProfit($this->uid);
        $rs['info'] = $info;
        return $rs;
    }

    /**
     * 红包规则
     * @desc 红包收益
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function redrule(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->redrule();
        $rs['info'] = $info;
        return $rs;
    }

    /**
     * 参加任务，我的余额
     * @desc 我的余额
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function  mybalance(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->mybalance($this->uid,$this->task_id);
        $rs['info'] = $info;
        return $rs;
    }


    /**
     * 发起任务，我的余额
     * @desc 我的余额
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function  mybalance2(){
        $rs = array('code' => 0, 'msg' => '操作成功', 'info' => array());
        $domain = new Domain_RedBagGame();
        $info = $domain->mybalance2($this->uid);
        $rs['info'] = $info;
        return $rs;
    }


}